<?php
/**
 * 推荐类
 * @author  zhanghui 
 * @create_date 2008-02-28
 */

class Recommend{
	function __construct(){}
	function __destruct(){}
	
	/** 添加推荐记录
	* @param  :$conn 数据库连接类
	* @param : id,recommend_type,baby_id,postid,recommend_menuid,recommend_folderid,recommend_baby_id,recommend_date
	 */
	function addRecommend($conn,$arr_input){
		$str_query = "insert into";
		$str_query .= " baby_recommend";
		$str_query .= " set";
		$str_query .= " recommend_type={$arr_input['recommend_type']}";
		$str_query .= ",baby_id={$arr_input['baby_id']}";
		$str_query .= ",postid={$arr_input['postid']}";
		$str_query .= ",recommend_menuid={$arr_input['recommend_menuid']}";
		$str_query .= ",recommend_folderid={$arr_input['recommend_folderid']}";	
		$str_query .= ",recommend_baby_id={$arr_input['recommend_baby_id']}";
		$str_query .= ",recommend_date='".$conn->getCurrentTime."'";
        
		$conn->executeQuery($str_query);
	} 
	
	/** 获取推荐记录
	* @param  :$conn 数据库连接类
    * @param : id,recommend_type,baby_id,postid,recommend_menuid,recommend_folderid,recommend_baby_id,recommend_date
	*/
	function getRecommendList($conn,$arr_input,$limit = null){
		$str_query = "select";
		if(isset($arr_input['cnt'])){
			$str_query .= " count(1)";
		}else{
			$str_query .= " id";
			$str_query .= ",recommend_type";
			$str_query .= ",baby_id";
			$str_query .= ",postid";
			$str_query .= ",recommend_menuid";
			$str_query .= ",recommend_folderid";
			$str_query .= ",recommend_baby_id";
			$str_query .= ",recommend_date";
		}
		$str_query .= " from";
		$str_query .= " baby_recommend";
		$str_query .= " where";
		$str_query .= " recommend_type={$arr_input['recommend_type']}";
		
		if(isset($arr_input['recommend_menuid'])){
			$str_query .= "recommend_menuid={$arr_input['recommend_menuid']}";
		}
		/**********************************************************************************************/
		$str_query .= " id={$arr_input['id']}";
		
		 if (isset($arr_input['orderby'])) {
        	$str_query .= " order by {$arr_input['orderby']}";
        }
        if ($limit != null){
        	$str_query .= " {$limit}";
        }
        
		$arr_output = $conn->selectQuery($str_query);
		return $arr_output;
	} 
	
	/** 设置推荐推荐记录（通过） 
	 * @param  :$conn 数据库连接类
     * @param : id,recommend_type,baby_id,postid,recommend_menuid,recommend_folderid,recommend_baby_id,recommend_date
	 */
	function setRecommend($conn,$arr_input){
		$str_query = "update";
		$str_query .= " baby_recommend";
		$str_query .= " set";
		$str_query .= " recommend_type=2";
		$str_query .= " where";
		$str_query .= " id={$arr_input['id']}";
		
		$conn->executeQuery($str_query);
	}
}

?>